
public class Room {
	
	private int cantA;
	private int cantB;
	
	public Room(){
		cantA=0;
		cantB=0;
	}
	
	 synchronized public void EntraA(){
		cantA++;	
		System.out.println("Entra A, cant A=" + String.valueOf(cantA));
		notifyAll();
	}
	
	 synchronized public void EntraB(){
		cantB++;	
		System.out.println("Entra B, cant B=" + String.valueOf(cantB));
		notifyAll();
	}
	
	 synchronized public void SaleA(){
		while(cantB<2 || cantA==0){
				System.out.println("No puede salir A");
				try {
					wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();	
				}
				System.out.println("Despierta wait() de salida A");
			}
		cantA--;
		System.out.println("Sale A, cant A=" + String.valueOf(cantA));	
	 }
	
	 synchronized public void SaleB(){
		while(cantA<1 || cantB==0){
			try {
				System.out.println("No puede salir B");
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("Despierta wait de salida B");
		}
		cantB--;
		System.out.println("Sale B, cant B=" + String.valueOf(cantB));
	}
}
